package com.taldh.springframework.beanlifecycle;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class LifecycleMain {

    @Bean(initMethod = "initMethod", destroyMethod = "destroyMethod")
    public BeanLifecycle beanLifecycle() {
        return new BeanLifecycle();
    }

    @Bean(initMethod = "initMethod", destroyMethod = "destroyMethod")
    public BeanLifecycle beanLifecycle2() {
        return new BeanLifecycle();
    }

    public static void main(String[] args) {
//        ConfigurableApplicationContext context = new SpringApplication().run(LifecycleMain.class);
//        context.close(); //这个方法用来触发destroy-method
//        context.getBeanFactory().(beanLifecycle2);
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.getBeanFactory().addBeanPostProcessor(new BeanPostProcessorTest());
        context.register(BeanLifecycle.class);
        context.refresh();

//
//
//
//        context.register(BeanLifecycle.class);

    }
}
